package com.hy.mydesktop.client.component.factory;

import java.util.List;

import com.extjs.gxt.ui.client.widget.form.CheckBox;
import com.extjs.gxt.ui.client.widget.form.CheckBoxGroup;
import com.extjs.gxt.ui.client.widget.form.Radio;
import com.hy.mydesktop.client.component.meta.AbstractComponetModelEnum;
import com.hy.mydesktop.client.component.meta.CheckBoxGroupModelEnum;
import com.hy.mydesktop.client.component.meta.TextFieldModelEnum;
import com.hy.mydesktop.shared.persistence.domain.gxt.GxtComponentMetaNodeModel;
/**
 * 
 * <ul>
 * <li>开发作者：冬超</li>
 * <li>设计日期：2010-8-29；时间：下午05:12:58</li>
 * <li>类型名称：CheckBoxGroupFactory</li>
 * <li>设计目的：</li>
 * </ul>
 * <ul>
 * <b>修订编号：</b>
 * <li>修订日期：</li>
 * <li>修订作者：</li>
 * <li>修订原因：</li>
 * <li>修订内容：</li>
 * </ul>
 */

public class CheckBoxGroupFactory {
	public static CheckBoxGroup createCheckBoxGroup(
			GxtComponentMetaNodeModel gxtComponentMetaNodeModel) {
		
		return configureCheckBoxGroup(gxtComponentMetaNodeModel);

	}

	/**
	 * 
	 * 
	 * @param gxtComponentMetaNodeModel
	 * @return
	 */
	private static CheckBoxGroup configureCheckBoxGroup(
			GxtComponentMetaNodeModel gxtComponentMetaNodeModel) {
		

		CheckBoxGroup checkBoxGroup = createDefaultCheckBoxGroup();
		checkBoxGroup = AbstractComponetFactory.configureAbstractComponet(checkBoxGroup, gxtComponentMetaNodeModel);
	
		if(gxtComponentMetaNodeModel.get(AbstractComponetModelEnum.CHILDREN.name().toLowerCase())!=null){
			//添加子控件
		 List<GxtComponentMetaNodeModel> list =(List<GxtComponentMetaNodeModel>)gxtComponentMetaNodeModel.get(AbstractComponetModelEnum.CHILDREN.name().toLowerCase());
		
		 for(int i=0;i<list.size();i++)
			{
				CheckBox checkBox=CheckBoxFactory.createCheckBox(list.get(i));
				
				checkBoxGroup.add(checkBox);
			}			
	}
		
		
		if(gxtComponentMetaNodeModel.get(TextFieldModelEnum.VALUE.name().toLowerCase())!=null){
			//设置值
			//checkBoxGroup.setValue((Boolean)gxtComponentMetaNodeModel.get(TextFieldModelEnum.VALUE.name().toLowerCase()));
		}
		if(gxtComponentMetaNodeModel.get(TextFieldModelEnum.FIELDLABEL.name().toLowerCase())!=null){
			//设置标签
			checkBoxGroup.setFieldLabel((String)gxtComponentMetaNodeModel.get(TextFieldModelEnum.FIELDLABEL.name().toLowerCase()));
		}
		if(gxtComponentMetaNodeModel.get(TextFieldModelEnum.NAME.name().toLowerCase())!=null){
			//设置控件名
			checkBoxGroup.setName((String)gxtComponentMetaNodeModel.get(TextFieldModelEnum.NAME.name().toLowerCase()));
		}
		
		
		if (gxtComponentMetaNodeModel.get(CheckBoxGroupModelEnum.LABEL.name()
				.toLowerCase()) != null) {
			String fieldLabel = (String) gxtComponentMetaNodeModel
					.get(CheckBoxGroupModelEnum.LABEL.name().toLowerCase());
			checkBoxGroup.setFieldLabel(fieldLabel);

		} 

		return checkBoxGroup;
	}

	private static CheckBoxGroup createDefaultCheckBoxGroup() {

		CheckBoxGroup checkBoxGroup = new CheckBoxGroup();
		return checkBoxGroup;
	}
}
